<?php
class Download_artwork extends Controller {

    function __construct()
    {
        parent::__construct();
        
    }
    
    function download_pdf()//To download just call: http://your.server/download_artwork/download_pdf/name_of_file.pdf
    {
        $path = site_url()."uploads/artwork/"; 
        $fullPath = str_replace('_','.',$path.$this->uri->segment(3));
         
        if ($fd = fopen ($fullPath, "r")) {
            //echo $fsize = filesize($fullPath);
            $path_parts = pathinfo($fullPath);
            $ext = strtolower($path_parts["extension"]);
            switch ($ext) {
                case "pdf":
                header("Content-type: application/pdf"); // add here more headers for diff. extensions
                header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a download
                break;
                default;
                header("Content-type: application/octet-stream");
                header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
            }
           // header("Content-length: $fsize");
            header("Cache-control: private"); //use this to open files directly
            while(!feof($fd)) {
                $buffer = fread($fd, 2048);
                echo $buffer;
            }
        }
        fclose ($fd);
        exit;
    }
}
?>